<template>
  <ul class="switches">
    <li class="switch-item"
    @click="selectItem(index)"
    v-for="(item, index) of switches"
    :key="index"
    :class="{active: currentIndex === index}"
    >
      <span>{{item.name}}</span>
    </li>
  </ul>
</template>
<script>
export default {
  name: 'Switches',
  props: {
    switches: {
      type: Array,
      default: () => []
    },
    currentIndex: {
      type: Number,
      default: 0
    }
  },
  methods: {
    selectItem (index) {
      this.$emit('selected', index)
    }
  }
}
</script>
<style lang="scss" scoped>
  @import 'common/scss/variable.scss';
  .switches{
    display: flex;
    align-items: center;
    width: 4.8rem;
    margin: 0 auto;
    border: 1px solid $color-highlight-background;
    border-radius: 0.1rem;
    .switch-item{
      flex: 1;
      padding: 0.16rem;
      text-align: center;
      font-size: $font-size-medium;
      color: $color-text-d;
      &.active{
        background: $color-highlight-background;
        color: $color-text;
      }
    }
  }
</style>
